import axios from 'axios';
import { message } from 'antd';
const instance = axios.create({
});

instance.interceptors.request.use(async config => {
    const token = localStorage.getItem('xxx-token') || 'xxx';
    config.headers['x-token'] = token;
    return config;
});

instance.interceptors.response.use(function (response) {
    const _response = response.data;

        // message.error('用户尚未登录或已过期，请重新登录', 0.8).then(() => {
        //     window.location.href = '#/login';
        // })
    
    return _response;
}, function (error) {
    console.log('error', error);
    switch (error.status) {
        case 404:
            message.error('请求的资源不存在');
            break;
        case 500:
            message.error('服务器内部错误');
            break;
        default:
            message.error('未知错误');
            break;
    }
});

export default instance;